<?php

/**
 * 商品管理
 * @author Ice iceinto@mallog.com.cn
 */
class GoodModel extends BaseModel {

	//自动验证
	protected $_validate = array(
			array('bid', 'require', '品牌必须！'),
			array('pid', 'require', '类型必须！'),
			array('price', 'require', '价格必须！'),
			array('name', 'require', '名称必须！'),
			array('material', 'require', '材质必须！'),
			array('image', 'require', '图片必须！'),
			array('intr', 'require', '简介必须！'),
			array('name', '', '中文名称已经存在！', 0, 'unique', 3),
	);
	//自动完成
	protected $_auto = array(
			array('create_time', 'time', self::MODEL_INSERT, 'function'),
			array('update_time', 'time', self::MODEL_UPDATE, 'function')
	);
	public function getGoodALlProPage($where = null) {
		$count = $this->where($where)->count();
		$Page = $this->getPage($count);
		$goods = $this->order('m_good.id desc')
		->limit($Page->firstRow . ',' . $Page->listRows)
		->join('LEFT JOIN m_brand ON m_brand.id = m_good.bid')
		->join('LEFT JOIN m_brand_pro ON m_brand.pid = m_brand_pro.id')
		->join('LEFT JOIN m_good_pro ON m_good.pid = m_good_pro.id')
		->field('m_good.id,m_good.name,m_good.article_number,m_brand.name as brand_name,m_brand_pro.name as brand_pro_name,m_good_pro.name as good_pro_name')
		->where($where)
		->select();
		$show = $Page->show();
		return array('page' => $show, 'data' => $goods);
	}

}